package com.qf.blog.service.impl;

import com.qf.blog.entity.DiscussPost;
import com.qf.blog.mapper.DiscussPostMapper;
import com.qf.blog.service.IDiscussPostService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.qf.blog.vo.PostVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author toString
 * @since 2024-05-21
 */
@Service
public class DiscussPostServiceImpl extends ServiceImpl<DiscussPostMapper, DiscussPost> implements IDiscussPostService {

    @Autowired
    private StringRedisTemplate stringRedisTemplate;

    private  String postScoreKey = "blog:post:score";

    @Override
    public List<PostVo> getPostVoList(Integer orderMode) {
        return baseMapper.getPostVoList(orderMode);
    }

    @Override
    public void addComputeQueue(Integer postId) {
        stringRedisTemplate.opsForSet().add(postScoreKey, postId.toString());
    }

    @Override
    public Long getPostQueueSize() {
        return stringRedisTemplate.opsForSet().size(postScoreKey);
    }

    @Override
    public Integer getPostQueuePop() {
        String pop = stringRedisTemplate.opsForSet().pop(postScoreKey);
        return Integer.parseInt(pop);
    }
}

